<?php

namespace app\index\model;
use think\Model;
use think\Db;

class TripModel extends Model
{
    protected $name = 'trip';
    
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = false;


    public  function getTripCate(){
        $main_cate = $this->where('pid',0)->select();
        foreach($main_cate as &$val)
        {
            $val['sub_category'] = $this->select('id as sub_category_id','name as sub_category_name')->where('pid',$val->category_id)->get();
        }

        return $main_cate;
    }

    /**
     * 根据搜索条件获取用户列表信息
     * @author [魏文峰]
     */
    public function getTripByWhere($id)
    {

        $getTripCateInfo = self::where('cate_id','=',$id)->select();
        return $getTripCateInfo;
    }
    //旅程详情
    public function getTripDetailInfo($id)
    {
        return $this->where('id',$id)->find();
    }
    //获取分类
    public  function tripCate(){
        return $this->hasOne('TripCateModel','id','cate_id');
    }

    //获取推荐旅程
    public function getTripRecom()
    {
        return $this->where('is_recom',1)->order('create_time desc')->select();
    }

    //获取精品旅程
    public function getTripJp()
    {
        return $this->where('is_jp',1)->order('create_time desc')->select();
    }

    //最新旅程
    public function getNewTrip()
    {
        return $this->limit(3)->order('create_time desc')->select();
    }

    //获取价格
    public function getOneTripPrice($id)
    {
        return $this->where('id', $id)->field('price_content')->find();
    }

}